package com.goldplusgold.tradedelay.app.market.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.goldplusgold.tradedelay.app.R;
import com.goldplusgold.tradedelay.app.base.listeners.Interface;
import com.goldplusgold.network.lib.http.protobuf.Market;

/**
 * Created by Administrator on 2017/3/10.
 */

public class TDTypeSelectPopup extends PopupWindow implements View.OnClickListener {

    private TextView btnAu;

    private TextView btnAg;

    private TextView btnMau;
    private Activity mContext;
    private LayoutInflater mInflater;
    private View rootView;
    private Market.InstType mPosition;
    private Interface.OnTDTypeClickListener mListener;

    public TDTypeSelectPopup(Activity context, Market.InstType position) {
        this.mContext = context;
        this.mPosition = position;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        initView();
    }

    private void initView() {
        rootView = mInflater.inflate(R.layout.popup_view_select_td_type, null);
        setContentView(rootView);
        setFocusable(true);
        setOutsideTouchable(true);
        //setAnimationStyle(R.style.AnimBottom);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(new BitmapDrawable());
        btnAu = (TextView) rootView.findViewById(R.id.btn_au);
        btnAg = (TextView) rootView.findViewById(R.id.btn_ag);
        btnMau = (TextView) rootView.findViewById(R.id.btn_mau);
        switch (mPosition) {
            case AU_TD:
                btnAu.setSelected(true);
                break;
            case AG_TD:
                btnAg.setSelected(true);
                break;
            case MAU_TD:
                btnMau.setSelected(true);
                break;
        }
        btnAu.setOnClickListener(this);
        btnAg.setOnClickListener(this);
        btnMau.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.btn_au:
                btnAu.setSelected(true);
                btnAg.setSelected(false);
                btnMau.setSelected(false);
                mListener.onTypeSet(1);
                dismiss();
                break;
            case R.id.btn_ag:
                btnAu.setSelected(false);
                btnAg.setSelected(true);
                btnMau.setSelected(false);
                mListener.onTypeSet(2);
                dismiss();
                break;
            case R.id.btn_mau:
                btnAu.setSelected(false);
                btnAg.setSelected(false);
                btnMau.setSelected(true);
                mListener.onTypeSet(3);
                dismiss();
                break;
        }

    }

    public void setTDTypeClickListener(Interface.OnTDTypeClickListener listener) {
        mListener = listener;
    }
}
